<?php

//初始化
include('init.php');

include_once('./smarty_init.php');
include_once('./libs/db.php');

//登录信息
$login_info = '';

$username = '';
$password = '';

//第一次打开页面
if(@$_REQUEST['act'] == '' && @$_SESSION['user_info'] == ''){
	$smarty->assign('login_info', "");

	$smarty->display('login.html');
}

//点击登录按钮
if(@$_REQUEST['act'] == '登录'){
	if($_POST['username'] == '' || $_POST['password'] == ''){
		$login_info = '<b><font color=red>用户名或密码不能为空!</font></b>';
	}else{
	
		$username = $_POST['username'];
		$password = $_POST['password'];
		
		$sql = "select * from _user where username = '$username' and password = password('$password')";
		
		$result = queryStr($sql);
		
		if($result['num_rows'] != 0){
			@$_SESSION['user_info'] = $result['rows'][0];

			$smarty->assign('login_info', $login_info);
			
			header("Location:index.php");
			
			exit;
		}else{
			$login_info = '<b><font color=red>用户名或密码错误!</font></b>';
		}
	}
}

//登出系统
if(@$_REQUEST['act'] == 'logout'){
	header("content-type:text/html; charset=utf-8");
	echo "<script>alert('登出系统成功!')</script>";
	
	unset($_SESSION['user_info']);

	echo "<script>location='login.php'</script>";
	
}



?>